<template>
  <div class="container" ref="container">
    <iframe ref="iframe" :src="iframeUrl" frameborder="0" width="100%" height="100%"></iframe>
  </div>
</template>

<script setup name="WarmFlow">
const { proxy } = getCurrentInstance();
import { onMounted } from 'vue';

const iframeUrl = ref(`${import.meta.env.VITE_APP_IFRAME_URL}/flow-design/index/${proxy.$route.params.id}?disabled=${proxy.$route.query.disabled}&pageNum=${proxy.$route.query.pageNum}`);
 
const iframeLoaded = () => {
  window.onmessage = (event) => {
    if (event.origin === import.meta.env.VITE_APP_IFRAME_URL) {
      switch (event.data.method) {
        case "close":
          close();
          break;
      }
    }
  }
};

/** 关闭按钮 */
function close() {
  const obj = { path: "/flow/definition", query: { t: Date.now(), pageNum: proxy.$route.query.pageNum } };
  proxy.$tab.closeOpenPage(obj);
}
 
onMounted(() => {
  iframeLoaded();
});
</script>

<style scoped>
.container {
  width: 100%;
  height: calc(100vh - 84px);
}
</style>
